package suanfa;

import org.junit.Test;

public class RegexSolution
{
    public boolean isMatch(String text, String pattern) {

        //如果字符串为null，返回false
        if (text == null || pattern == null)
        {
            return false;
        }
        //如果没有包含这个符号，就直接进行对比
        if (!pattern.contains(".") || !pattern.contains("*"))
        {
            return text.equals(pattern);
        }
        char[] texts = text.toCharArray();
        char[] patterns = pattern.toCharArray();
        char[] chars = new char[texts.length];
        for (int i = 0; i < patterns.length; i++)
        {
            for (int j = i; j < texts.length; j++)
            {
                if (texts[i] == patterns[j])
                {
                    //如果相同，就继续
                    chars[i] = texts[i];
                    continue;
                }
                //如果遇到'.'的，就替换掉
                if (patterns[i] == '.')
                {
                    //新的数组增加这个参数
                    chars[i] = texts[i];
                    continue;
                }
                //如果有带'*'号的
                if (patterns[i] == '*')
                {
                    if (texts[i] == texts[i - 1])
                    {
                        chars[i] = texts[i];
                    }else
                    {
                        continue;
                    }
                }

            }
        }

        return chars == texts;
    }

    @Test
    public void test()
    {
        System.out.println(isMatch("ssss", "s.*"));
    }
}
